from pydantic import Field, BaseModel
from typing import List


class Configure(BaseModel):
    """登陆安全配置"""
    description: str = Field(..., title='配置描述')


class ConfigureOut(BaseModel):
    """登陆安全配置"""
    name: str = Field(..., title='配置名')

    class Config:
        orm_mode = True


class _Login(BaseModel):
    """登陆配置"""
    lock_window: int = Field(60, title='锁定周期')
    lock_time: int = Field(180, title='锁定时长')
    max_retry_times: int = Field(3, title='最大重试次数')
    lock_user: bool = Field(True, title='锁定用户')
    lock_ip: bool = Field(False, title='锁定IP')


class _BlackIP(BaseModel):
    """地址黑名单"""
    black_list: List[str] = Field(..., title='黑名单')


class _DiskThreshold(BaseModel):
    """磁盘阈值"""
    rate: int = Field(10, title='比例 %')
    reclaim: int = Field(100, title='回收阈值 G')


class _RoleMap(BaseModel):
    """权限地图"""
    module: str = Field(..., title='模块')
    name: str = Field(..., title='模块名')
    scopes: List[dict] = Field(..., title='功能函数')


class _SessionTimeout(BaseModel):
    """会话超时"""
    timeout: int = Field(0, title='会话超时')


class Login(Configure):
    config: _Login = Field(..., title='登陆安全')


class BlackIP(Configure):
    config: _BlackIP = Field(..., title='地址黑名单')


class DiskThreshold(Configure):
    config: _DiskThreshold = Field(..., title='磁盘阈值')


class SessionTimeout(Configure):
    config: _SessionTimeout = Field(..., title='会话阈值')


class RoleMap(Configure):
    config: List[_RoleMap] = Field(..., title='权限树')


class LoginOut(Login, ConfigureOut):
    pass


class BlackIPOut(ConfigureOut, BlackIP):
    pass


class DiskThresholdOut(ConfigureOut, DiskThreshold):
    pass


class SessionTimeoutOut(ConfigureOut, SessionTimeout):
    pass


class RoleMapOut(ConfigureOut, RoleMap):
    pass
